package com.agile.familytree.service;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;

import com.agile.familytree.datastructure.*;
import com.agile.familytree.business.*;

public class GedcomProcessService {
	
	public static void main(String[] args) {
		
		String fileName = new String();

		if( args!=null && args.length>0 ){
			fileName = args[0];
		}
		else{
			fileName = "C:/Temp/Family_Sprint3_Test.ged";
			//fileName = "C:/Temp/Family_testSprint2.ged";
		}
			
		new GedcomProcessService().execute(fileName);
	}
	
	private void execute(String fileName){
		
		List<Person> lPerson = new ArrayList<Person>();
		List<Family> lFamily = new ArrayList<Family>();
		BufferedReader readerGedcom = null;
		
		//task1
		try{
			readerGedcom = new FileLoader().loadData(fileName);
		}
		catch(Exception e){
			System.out.println("Exception thrown during task1, please investigate..");
			e.printStackTrace();
		}

		//task2
		try{
			new BeanProducer().processData(readerGedcom, lPerson, lFamily);
		}
		catch(Exception e){
			System.out.println("Exception thrown during task2, please investigate..");
			e.printStackTrace();
		}

		//task3
		try{
			OutputDisplayer.displayData(lPerson, lFamily);			
		}
		catch(Exception e){
			System.out.println("Exception thrown during task3, please investigate..");
			e.printStackTrace();
		}
		
		
		Validator validator = new Validator();

		//task4
		try{
			validator.validateDeathBeforeBirth(lPerson);
		}
		catch(Exception e){
			System.out.println("Exception thrown during task4, please investigate..");
			e.printStackTrace();
		}

		//task5
		try{
			validator.validateMarriageToTheDead(lFamily);
		}
		catch(Exception e){
			System.out.println("Exception thrown during task5, please investigate..");
			e.printStackTrace();
		}
		
		
		//task6
		try{
			validator.validateMarriedToSibling(lPerson, lFamily);
		}
		catch(Exception e){
			System.out.println("Exception thrown during tas6, please investigate..");
			e.printStackTrace();
		}

		//task7
		try{
			validator.validatePoligamy(lFamily);
		}
		catch(Exception e){
			System.out.println("Exception thrown during task7, please investigate..");
			e.printStackTrace();
		}
	}
	
}
